package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.GoToRegister;
import com.cpj.bsyyzx.entity.LifePlan;
import com.cpj.bsyyzx.entity.NContent;
import com.cpj.bsyyzx.service.ILifePlanService;
import com.cpj.bsyyzx.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/lifePlan")

public class LifePlanController {
    @Autowired
   ILifePlanService lifePlanService;

    @RequestMapping("/list")
    CommonResult list(Page page, LifePlan lifePlan){
        QueryWrapper<LifePlan> queryWrapper = new QueryWrapper<>();
        Page<LifePlan> rpage=lifePlanService.pageList(page, lifePlan);
        return CommonResult.success(rpage);
    }

    @RequestMapping("save")
    @ResponseBody
    CommonResult save(LifePlan lifePlan) {
        Map map = new HashMap();
        boolean success = lifePlanService.saveOrUpdate(lifePlan);
        return CommonResult.success(success);
    }

    @RequestMapping("toedit")
    @ResponseBody
    public CommonResult toedit(ModelMap map, Integer id) {

//        LifePlan lifePlan = lifePlanService.getById(plan_id);
//        map.addAttribute("lifePlan", lifePlan);
        return CommonResult.success(lifePlanService.getById(id));
    }

    @RequestMapping("delete/{plan_id}")
    @ResponseBody
    CommonResult delete(@PathVariable Integer plan_id) {
        boolean success = lifePlanService.removeById(plan_id);
        return CommonResult.success(success);
    }


}
